home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / Issue50 / Clinic / FontDlgU.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1999-08-04  |  1.3 KB  |  55 lines

  1. unit FontDlgU;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  7.   StdCtrls, ComCtrls, Buttons;
  8.  
  9. type
  10.   TForm1 = class(TForm)
  11.     FDlg: TFontDialog;
  12.     Edit1: TEdit;
  13.     SpeedButton1: TSpeedButton;
  14.     RichEdit1: TRichEdit;
  15.     procedure SpeedButton1Click(Sender: TObject);
  16.     procedure FDlgApply(Sender: TObject; Wnd: HWND);
  17.   private
  18.     { Private declarations }
  19.   public
  20.     { Public declarations }
  21.   end;
  22.  
  23. var
  24.   Form1: TForm1;
  25.  
  26. implementation
  27.  
  28. {$R *.DFM}
  29.  
  30. procedure TForm1.SpeedButton1Click(Sender: TObject);
  31. begin
  32.   if ActiveControl is TEdit then
  33.     FDlg.Font := TEdit(ActiveControl).Font
  34.   else
  35.     if ActiveControl is TRichEdit then
  36.       TRichEdit(Activecontrol).SelAttributes.Assign(FDlg.Font);
  37.   //Launch dialog. If it returns True, and
  38.   //we have an OnApply handler, call it
  39.   if FDlg.Execute and Assigned(FDlg.OnApply) then
  40.     FDlg.OnApply(FDlg, 0)
  41. end;
  42.  
  43. procedure TForm1.FDlgApply(Sender: TObject; Wnd: HWND);
  44. begin
  45.   //Could check here that there is in fact a need to apply
  46.   //the font, by comparing, but for brevity, I'll skip it
  47.   if ActiveControl is TEdit then
  48.     TEdit(ActiveControl).Font := TFontDialog(Sender).Font
  49.   else
  50.     if ActiveControl is TRichEdit then
  51.       TRichEdit(ActiveControl).SelAttributes.Assign(TFontDialog(Sender).Font)
  52. end;
  53.  
  54. end.
  55.